package site.assad.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import site.assad.model.User;
import site.assad.service.UserService;

/**
 * Author: Al-assad 余林颖
 * E-mail: yulinying_1994@outlook.com
 * Date: 2018/1/12 14:09
 * Description: 用于演示AJAX协同的控制器
 */
@Controller
public class AjaxController {

    @Autowired
    private UserService userService;

    @RequestMapping("/ajax")
    public String toAjaxPage(){
        return "ajaxTest";
    }

    @RequestMapping(value="/getUserAjax",method=RequestMethod.GET)
    public ResponseEntity<User> handleUserAjax(@RequestParam("userId") int userId){
        User user = userService.getUser(userId);
        ResponseEntity<User> responseEntity  = new ResponseEntity<>(user, HttpStatus.OK);
        return responseEntity;
    }

}
